using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace SubSonic.Generated
{
	/// <summary>
	/// Strongly-typed collection for the FriendX class.
	/// </summary>
    [Serializable]
	public partial class FriendXCollection : ActiveList<FriendX, FriendXCollection>
	{	   
		public FriendXCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>FriendXCollection</returns>
		public FriendXCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                FriendX o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the friends table.
	/// </summary>
	[Serializable]
	public partial class FriendX : ActiveRecord<FriendX>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public FriendX()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public FriendX(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public FriendX(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public FriendX(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("friends", TableType.Table, DataService.GetInstance("sqlite"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"main";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "id";
				colvarId.DataType = DbType.Int64;
				colvarId.MaxLength = 8;
				colvarId.AutoIncrement = true;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarHostname = new TableSchema.TableColumn(schema);
				colvarHostname.ColumnName = "hostname";
				colvarHostname.DataType = DbType.String;
				colvarHostname.MaxLength = 2147483647;
				colvarHostname.AutoIncrement = false;
				colvarHostname.IsNullable = false;
				colvarHostname.IsPrimaryKey = false;
				colvarHostname.IsForeignKey = false;
				colvarHostname.IsReadOnly = false;
				colvarHostname.DefaultSetting = @"";
				colvarHostname.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHostname);
				
				TableSchema.TableColumn colvarRsaparamXMLString = new TableSchema.TableColumn(schema);
				colvarRsaparamXMLString.ColumnName = "rsaparamXMLString";
				colvarRsaparamXMLString.DataType = DbType.String;
				colvarRsaparamXMLString.MaxLength = 2147483647;
				colvarRsaparamXMLString.AutoIncrement = false;
				colvarRsaparamXMLString.IsNullable = false;
				colvarRsaparamXMLString.IsPrimaryKey = false;
				colvarRsaparamXMLString.IsForeignKey = false;
				colvarRsaparamXMLString.IsReadOnly = false;
				colvarRsaparamXMLString.DefaultSetting = @"";
				colvarRsaparamXMLString.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRsaparamXMLString);
				
				TableSchema.TableColumn colvarPort = new TableSchema.TableColumn(schema);
				colvarPort.ColumnName = "port";
				colvarPort.DataType = DbType.Int64;
				colvarPort.MaxLength = 8;
				colvarPort.AutoIncrement = false;
				colvarPort.IsNullable = false;
				colvarPort.IsPrimaryKey = false;
				colvarPort.IsForeignKey = false;
				colvarPort.IsReadOnly = false;
				colvarPort.DefaultSetting = @"";
				colvarPort.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPort);
				
				TableSchema.TableColumn colvarHandle = new TableSchema.TableColumn(schema);
				colvarHandle.ColumnName = "handle";
				colvarHandle.DataType = DbType.String;
				colvarHandle.MaxLength = 2147483647;
				colvarHandle.AutoIncrement = false;
				colvarHandle.IsNullable = false;
				colvarHandle.IsPrimaryKey = false;
				colvarHandle.IsForeignKey = false;
				colvarHandle.IsReadOnly = false;
				colvarHandle.DefaultSetting = @"";
				colvarHandle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarHandle);
				
				TableSchema.TableColumn colvarOnLAN = new TableSchema.TableColumn(schema);
				colvarOnLAN.ColumnName = "onLAN";
				colvarOnLAN.DataType = DbType.Boolean;
				colvarOnLAN.MaxLength = 1;
				colvarOnLAN.AutoIncrement = false;
				colvarOnLAN.IsNullable = false;
				colvarOnLAN.IsPrimaryKey = false;
				colvarOnLAN.IsForeignKey = false;
				colvarOnLAN.IsReadOnly = false;
				colvarOnLAN.DefaultSetting = @"";
				colvarOnLAN.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOnLAN);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["sqlite"].AddSchema("friends",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("Id")]
		[Bindable(true)]
		public long Id 
		{
			get { return GetColumnValue<long>(Columns.Id); }
			set { SetColumnValue(Columns.Id, value); }
		}
		  
		[XmlAttribute("Hostname")]
		[Bindable(true)]
		public string Hostname 
		{
			get { return GetColumnValue<string>(Columns.Hostname); }
			set { SetColumnValue(Columns.Hostname, value); }
		}
		  
		[XmlAttribute("RsaparamXMLString")]
		[Bindable(true)]
		public string RsaparamXMLString 
		{
			get { return GetColumnValue<string>(Columns.RsaparamXMLString); }
			set { SetColumnValue(Columns.RsaparamXMLString, value); }
		}
		  
		[XmlAttribute("Port")]
		[Bindable(true)]
		public long Port 
		{
			get { return GetColumnValue<long>(Columns.Port); }
			set { SetColumnValue(Columns.Port, value); }
		}
		  
		[XmlAttribute("Handle")]
		[Bindable(true)]
		public string Handle 
		{
			get { return GetColumnValue<string>(Columns.Handle); }
			set { SetColumnValue(Columns.Handle, value); }
		}
		  
		[XmlAttribute("OnLAN")]
		[Bindable(true)]
		public bool OnLAN 
		{
			get { return GetColumnValue<bool>(Columns.OnLAN); }
			set { SetColumnValue(Columns.OnLAN, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varHostname,string varRsaparamXMLString,long varPort,string varHandle,bool varOnLAN)
		{
			FriendX item = new FriendX();
			
			item.Hostname = varHostname;
			
			item.RsaparamXMLString = varRsaparamXMLString;
			
			item.Port = varPort;
			
			item.Handle = varHandle;
			
			item.OnLAN = varOnLAN;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(long varId,string varHostname,string varRsaparamXMLString,long varPort,string varHandle,bool varOnLAN)
		{
			FriendX item = new FriendX();
			
				item.Id = varId;
			
				item.Hostname = varHostname;
			
				item.RsaparamXMLString = varRsaparamXMLString;
			
				item.Port = varPort;
			
				item.Handle = varHandle;
			
				item.OnLAN = varOnLAN;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn IdColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn HostnameColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn RsaparamXMLStringColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn PortColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn HandleColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn OnLANColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"id";
			 public static string Hostname = @"hostname";
			 public static string RsaparamXMLString = @"rsaparamXMLString";
			 public static string Port = @"port";
			 public static string Handle = @"handle";
			 public static string OnLAN = @"onLAN";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
